package com.fz.controller.system;

import com.fz.aop.login.AnonymousAccess;
import com.fz.common.ResponseEntity;
import com.fz.beans.PageBeans;
import com.fz.dto.system.role.RoleAdd;
import com.fz.dto.system.role.RoleMenuDto;
import com.fz.dto.system.role.RoleQuery;
import com.fz.dto.system.role.RoleUpd;
import com.fz.service.system.RoleService;
import com.fz.vo.system.menu.RoleMenuTreeVo;
import com.fz.vo.system.menu.MenuVo;
import com.fz.vo.system.role.RoleVo;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = "角色管理")
@RequestMapping("/role")
@ApiSort(value = 3)
@SuppressWarnings("unchecked")
public class RoleController {

    @Resource
    private RoleService roleService;

    @GetMapping("/findRoleList")
    @ApiOperation(value = "分页查询角色管理")
    @ApiOperationSupport(order = 1)
    @AnonymousAccess
    public ResponseEntity<RoleMenuTreeVo> findRoleList(RoleQuery roleQuery,PageBeans pageBeans) throws Exception{
        return roleService.findRoleList(pageBeans.getPageNum(),pageBeans.getPageSize(),roleQuery);
    }

    @GetMapping("/findMenuById")
    @ApiOperation(value = "根据角色查询菜单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleId",value = "角色id", required = true,dataType = "int",paramType = "query")
    })
    @ApiOperationSupport(order = 3)
    @AnonymousAccess
    public ResponseEntity<List<MenuVo>> findMenuById(int roleId) throws Exception{
        return roleService.findMenuById(roleId);
    }

    @GetMapping("/findRoleSelect")
    @ApiOperation(value = "获取角色下拉框")
    @ApiOperationSupport(order = 2)
    @AnonymousAccess
    public ResponseEntity<List<RoleVo>> findRoleSelect(RoleQuery roleQuery) throws Exception{
        return roleService.findRoleSelect(roleQuery);
    }

    @PostMapping("/addRole")
    @ApiOperation(value = "新增角色")
    @ApiOperationSupport(order = 4)
    @AnonymousAccess
    public ResponseEntity addRole(@RequestBody RoleAdd roleAdd) throws Exception{
        return roleService.addRole(roleAdd);
    }

    @PostMapping("/updateRole")
    @ApiOperation(value = "修改角色")
    @ApiOperationSupport(order = 5)
    @AnonymousAccess
    public ResponseEntity updateRole(@RequestBody RoleUpd roleUpd) throws Exception{
        return roleService.updateRole(roleUpd);
    }

    @PostMapping("/saveRoleMenu")
    @ApiOperation(value = "保存角色菜单")
    @ApiOperationSupport(order = 6)
    @AnonymousAccess
    public ResponseEntity saveRoleMenu(@RequestBody RoleMenuDto roleMenuDto) throws Exception{
        return roleService.saveRoleMenu(roleMenuDto);
    }
}